package fr.playsoft.psas;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;



//imageAdapter class    
public class CarrouselAdapter extends BaseAdapter 
{
	/** The parent context */
   		
	private int[] mArrImage;
	private LayoutInflater mInflater;
	
    /** Simple Constructor saving the 'parent' context. */
    public CarrouselAdapter(Context c, int[]array_Images) 
    {    
    	mInflater = LayoutInflater.from(c);
    	mArrImage = array_Images;
    }

    /** Returns the amount of images we have defined. */
    public int getCount() 
    {
    	int size = 0;
    	if(mArrImage != null)
    		size = mArrImage.length;
    	return size;
    }

    /* Use the array-Positions as unique IDs */
    public Object getItem(int position) 
    {     	
    	return position; 
    }
    
    public long getItemId(int position)
    { 
    	return position; 
    }
    
    public View getView(int position, View v, ViewGroup parent) 
    {    	
    	 BaseSrvImageHolder holder;
    	
		 if (v == null) 
		 {
			v = mInflater.inflate(R.layout.carrousel_item, null);
			
			holder = new BaseSrvImageHolder();
			holder.icon =(ImageView)v.findViewById(R.id.baseservice_img_gallery_item);
			holder.separatedLine = v.findViewById(R.id.baseservice_separated_line);
			v.setTag(holder);
		 } 
		 else 
		 {
			 holder = (BaseSrvImageHolder)v.getTag();
		 }
		 
		 holder.icon.setImageResource(mArrImage[position]);
		 if(position >= getCount() - 1)
			 holder.separatedLine.setVisibility(View.INVISIBLE);

		 return v;
    }
    
    private class BaseSrvImageHolder {
    	ImageView icon;
    	 View separatedLine;
    }
    
}